package com.threadPool.providerConsumer;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @author: dong peng
 * @date: 2019/6/3 18:26
 * @description:
 */

public class ShareResource {

    private BlockingQueue<String> queue = new LinkedBlockingQueue<>();

    public void  add(String s)   {
        try {

            queue.put(s);
            System.out.println("总数"+queue.size());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public String remove()   {
        try {
            return queue.poll(2, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return null;
    }
}
